import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrdersGoodsVO, OrdersGoodsForm, OrdersGoodsQuery } from '@/api/goods/goods/types';

/**
 * 查询商品列表
 * @param query
 * @returns {*}
 */

export const listOrdersGoods = (query?: OrdersGoodsQuery): AxiosPromise<OrdersGoodsVO[]> => {
  return request({
    url: '/order/ordersGoods/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商品详细
 * @param id
 */
export const getOrdersGoods = (id: string | number): AxiosPromise<OrdersGoodsVO> => {
  return request({
    url: '/order/ordersGoods/' + id,
    method: 'get'
  });
};

/**
 * 查询商品详细
 */
export const getOrdersGoodsAllList = (): AxiosPromise<OrdersGoodsVO> => {
  return request({
    url: '/order/ordersGoods/allList',
    method: 'get'
  });
};
/**
 * 生成商品编号
 */
export const getAutoItemNo = (): AxiosPromise<OrdersGoodsVO> => {
  return request({
    url: '/order/goods/getAutoItemNo',
    method: 'get'
  });
};

/**
 * 新增商品
 * @param data
 */
export const addOrdersGoods = (data: OrdersGoodsForm) => {
  return request({
    url: '/order/goods',
    method: 'post',
    data: data
  });
};
/**
 * 新增商品
 * @param data
 */
export const checkAutoItemNo = (data: OrdersGoodsForm) => {
  return request({
    url: '/order/goods/checkAutoItemNo',
    method: 'post',
    data: data
  });
};

/**
 * 新增商品
 * @param data
 */
export const customAdddictLabel = (data: any) => {
  return request({
    url: '/system/dict/data/customAdd',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品
 * @param data
 */
export const updateOrdersGoods = (data: OrdersGoodsForm) => {
  return request({
    url: '/order/goods',
    method: 'put',
    data: data
  });
};

/**
 * 删除商品
 * @param id
 */
export const delOrdersGoods = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/ordersGoods/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param goodsId 客户端id
 * @param status 状态
 */
export function changeStatus(goodsId: string, status: string) {
  const data = {
    goodsId,
    status
  };
  return request({
    url: '/order/ordersGoods/changeStatus',
    method: 'put',
    data: data
  });
}

// 刷新缓存
export const refreshCache = () => {
  return request({
    url: '/system/dict/type/refreshCache',
    method: 'delete'
  })
}

export default {
  list: listOrdersGoods,
  get: getOrdersGoods,
  add: addOrdersGoods,
  update: updateOrdersGoods,
  del: delOrdersGoods,
  getOrdersGoodsAllList: getOrdersGoodsAllList,
  getAutoItemNo: getAutoItemNo,
  checkAutoItemNo: checkAutoItemNo,
}